package tech.cn.note.word.fun;

import cn.hutool.core.convert.NumberChineseFormatter;
import com.deepoove.poi.render.compute.RenderDataCompute;

import org.springframework.stereotype.Service;

import static org.springframework.util.ObjectUtils.isEmpty;

@Service
public class ChineseMoney implements RenderFunction {
    /**
     * @param fields            参数1 数字
     * @param renderDataCompute
     * @return
     */
    @Override
    public String doCalculate(String[] fields, RenderDataCompute renderDataCompute) {
        if (isEmpty(fields)) {
            return "";
        }
        String placeHolder = fields[0];
        Object data = renderDataCompute.compute(placeHolder);
        if (data == null) {
            return "";
        }
        return NumberChineseFormatter.format(Double.parseDouble(data.toString()), true, true);
    }
}
